/*
 * @lc app=leetcode.cn id=912 lang=javascript
 *
 * [912] 排序数组
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortArray = function (nums) {
  for (let i = 1; i < nums.length; i++) {
    const temp = nums[i];

    let j = i - 1;
    while (j >= 0) {
      if (temp < nums[j]) {
        nums[j + 1] = nums[j];
        j--;
      } else {
        break;
      }
    }

    nums[j + 1] = temp;
  }

  return nums;
};
// @lc code=end

// @after-stub-for-debug-begin
module.exports = sortArray;
// @after-stub-for-debug-end
